package putao.ui
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import putao.ui.events.PRadioButtonEvent;
	import putao.ui.events.PSelectButtonEvent;
	
	[Event(name="PRadioButtonEvent_SELECT", type="putao.ui.events.PRadioButtonEvent")]
	
	public class PRadioButtonGroup extends EventDispatcher
	{
		private var name:String = "";
		
		private var radioButtonV:Vector.<PRadioButton>;
		
		public function PRadioButtonGroup(name:String = "")
		{
			super(null);
			
			this.name = name;
			radioButtonV = new Vector.<PRadioButton>();
		}
		
		public function addRadioButton(btn:PRadioButton):void
		{
			radioButtonV.push(btn);
			btn.addEventListener(PSelectButtonEvent.SELECT, onRadioSelect, false, 0, true);
		}
		
		private function onRadioSelect(e:PSelectButtonEvent):void
		{
			for(var i:int = 0; i < radioButtonV.length; i++)
			{
				if(radioButtonV[i] != e.currentTarget)
				{
					radioButtonV[i].unSelect();
				}else{
					var event:PRadioButtonEvent = new PRadioButtonEvent(PRadioButtonEvent.SELECT, true, false);
					event.id = i;
					dispatchEvent(event);
				}
			}
		}
	}
}